package com.itheima.app.mq;

import com.itheima.service.mongo.MovementService;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component // 记录用户动态行为的消息发送类
public class MovementMQSend {

    @Reference
    private MovementService movementService;

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    //针对动态的操作
    public static final Integer MOVEMENT_PUBLISH = 1;// 发动态
    public static final Integer MOVEMENT_BROWSE = 2;// 浏览动态
    public static final Integer MOVEMENT_LIKE = 3;// 点赞
    public static final Integer MOVEMENT_LOVE = 4;// 喜欢
    public static final Integer MOVEMENT_COMMENT = 5;// 评论
    public static final Integer MOVEMENT_DISLIKE = 6;// 取消点赞
    public static final Integer MOVEMENT_DISLOVE = 7;// 取消喜欢

    public void sendMovement(Long userId, String movementId, Integer type) {
        // 组装map
        Map<String, String> map = new HashMap<>();
        map.put("userId", userId.toString());
        map.put("pid", movementService.findMovementById(new ObjectId(movementId)).getPid().toString());
        map.put("type", type.toString());

        // 投递消息
        rocketMQTemplate.convertAndSend("recommend-movement", map);

    }

}
